# _*_ coding:utf8 _*_

import os
import cv2
from digit_calculate import get_char_list


if __name__ == '__main__':
    # 获取图像
    path_name = './test_data/'
    # 获取列表
    file_path_list = os.listdir(path_name)
    # 总字符数
    total_char_num = 0
    # 正确字符数
    total_right_char_num = 0
    # 总验证码数
    total_image_num = 0
    # 正确验证码数
    total_right_image_num = 0

    for i in range(0, len(file_path_list)):
        temp_name = file_path_list[i][:-4]
        temp_image = cv2.imread(path_name + file_path_list[i])
        recognition_char_list = get_char_list(temp_image)
        recognition_string = "".join(recognition_char_list)
        print(temp_name, recognition_string)

        # 统计
        total_char_num += len(temp_name)
        total_image_num += 1
        for j in range(len(temp_name)):
            if len(temp_name) > len(recognition_char_list):
                continue
            if temp_name[j] == recognition_char_list[j]:
                total_right_char_num += 1
        if temp_name.strip() == recognition_string.strip():
            total_right_image_num += 1
        else:
            print("I am wrong: " + temp_name)

    print("测试图片数：" + str(total_image_num))
    print("图片正确率：" + "{:.2f}%".format(total_right_image_num/total_image_num*100))
    print("测试字符数：" + str(total_char_num))
    print("字符正确率：" + "{:.2f}%".format(total_right_char_num/total_char_num*100))

